package com.ys.peony.ui.widget;

import android.content.Context;
import android.graphics.drawable.ColorDrawable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.PopupWindow;

import com.ys.peony.R;
import com.ys.peony.model.YWDJPrepareItemModel;
import com.ys.peony.ui.adapter.TypeValAdapter;
import com.ys.peony.utils.PixelUtils;

import java.util.List;

/**
 *0 客户基本信息-职务
 *1 客户基本信息-婚姻状况
 *2 客户基本信息-产权状态
 *3 客户基本信息-单位性质
 *4 客户基本信息-性别代码
 *5 车辆信息-产地
 *6 客户基本信息-是否有产权 0 否 1 是
 *7 车辆信息-权属标记
 *8 客户基本信息-行业
 * 下拉选择框
 */
public class TypeValPicker_Bak extends PopupWindow {
    private Context context;
    private View rootView;
    private TypeValCallBack callBack;

    private ListView optionLv;

    //listview 列表
    private List<YWDJPrepareItemModel> options;
    private TypeValAdapter adapter;
    private int type=0;//
    public TypeValPicker_Bak(Context context, TypeValCallBack callBack, int width) {
        super();
        this.context = context;
        this.callBack = callBack;
        initView(width);
        initRegistClickListener();
    }


    private void initView(int width) {
        rootView = LayoutInflater.from(context).inflate(R.layout.pop_typeval_layout_bak, null);
        setContentView(rootView);
        setWidth(width);
        setHeight(ViewGroup.LayoutParams.WRAP_CONTENT);
        setFocusable(true);
        ColorDrawable dw = new ColorDrawable(0x00ffffff);
        setBackgroundDrawable(dw);
        setOutsideTouchable(true);
        optionLv = (ListView) rootView.findViewById(R.id.option_lv);
        adapter=new TypeValAdapter(context,options);
        optionLv.setAdapter(adapter);
    }

    public interface TypeValCallBack {
        void pickerTypeValItemOnclick(String text, String val, int type);
    }

    private void initRegistClickListener() {
        optionLv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                if(callBack!=null){
                    callBack.pickerTypeValItemOnclick(options.get(position).getText(),options.get(position).getVal(),type);
                }
                dismiss();
            }
        });
    }



    public void show(View mRootView,List<YWDJPrepareItemModel> options,int type) {
        this.type=type;
        this.options=options;
        adapter.setData(options);
        //修改界面展示
        showAsDropDown(mRootView, 0, -PixelUtils.dip2px(10, context));
//        showAtLocation(mRootView, Gravity.BOTTOM, 0, 0);
    }
}
